package com.sc.servlet.user.notice;

import com.alibaba.fastjson.JSON;
import com.sc.pojo.Notice;
import com.sc.services.NoticeServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @description: 用户根据场地号查询该场地所有的公告
 * @author: sc
 * @create: 2023-01-06 02:12
 **/
@WebServlet("/selectNoticeByFieldId")
public class selectNoticeByFieldIdServlet extends HttpServlet {

    private NoticeServices noticeServices = new NoticeServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String fieldid = request.getParameter("fieldid");
        List<Notice> notices = noticeServices.selectNoticeById(Integer.parseInt(fieldid));


        //2. 转为JSON
        String jsonString = JSON.toJSONString(notices);

        //3. 写数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}